package com.yanqu.road.server.cmd.activity.langyabang.fromCross;

import com.yanqu.road.entity.activity.langyabang.data.LangYaBangWarReportData;
import com.yanqu.road.logic.pb.LangYaBangPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LangYaBangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.langyabang.LangYaBangModule;
import com.yanqu.road.server.manger.activity.langyabang.LangYaBangMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_LANG_YA_BANG_ACCEPT_CROSS_NOTICE,desc = "跨服受击返回本服战报")
public class LangYaBangNoticeFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        LangYaBangProto.LangYaWarReportSyncMsg msg = LangYaBangProto.LangYaWarReportSyncMsg.parseFrom(packet.getBytes());
        long userId = msg.getUserId();
        LangYaBangWarReportData warReportData = LangYaBangPb.parseMsgToNoticeData(msg.getData(),msg.getActivityId(),userId);

        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(userId);
        if (onlinePlayer != null){
            onlinePlayer.getModule(LangYaBangModule.class).addWarReportData(warReportData);
            onlinePlayer.getModule(LangYaBangModule.class).syncWarReportToUser(warReportData);
        }else {
            LangYaBangMgr.addWarReportToUser(warReportData);
        }

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
